#ifndef __GRID_POINT_H__
#define __GRID_POINT_H__

#include <iostream>
#include <sstream>
#include <algorithm>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

// Grid Point
class GP{
    public:
        GP(cv::Point point){
            this->point = point;
            this->cost_f = 0.0;
            this->cost_g = 0.0;
            this->cost_h = 0.0;
            this->parent = nullptr;
            this->id = this->Id();
        }
        GP(cv::Point point, float g, float h){
            this->point = point;
            this->cost_f = g + h;
            this->cost_g = g;
            this->cost_h = h;
            this->parent = nullptr;
            this->id = this->Id();
        }
        ~GP(){};

        string Id(){
            stringstream ss;
            ss << this->point.x << "_" << this->point.y;
            return ss.str();
        }

        string GetId(){
            return this->id;
        }

        // 设置父节点
        void SetParent(GP* parent){
            this->parent = parent;
        }

        // 获取父节点
        GP* GetParent(){
            return this->parent;
        }


        float UpdateCostF(float g, float h){
            this->cost_f = g + h;
            this->cost_g = g;
            this->cost_h = h;
        }

        // 获取代价
        float GetCostF(){
            return this->cost_f;
        }

        // 获取代价g
        float GetCostG(){
            return this->cost_g;
        }

        // 获取代价h
        float GetCostH(){
            return this->cost_h;
        }

        // 获取点
        cv::Point GetPoint(){
            return this->point;
        }
        
        bool operator > (GP& other){ 
            return this->cost_f > other.GetCostF();
        }

        bool operator < (GP& other){ 
            return this->cost_f < other.GetCostF();
        }

        bool operator == (GP& other){ 
            return this->cost_f == other.cost_f;
        }


    private:
        cv::Point point;
        float cost_f;
        float cost_g;
        float cost_h;
        string id;
        GP* parent;
};

struct GPcmp{
    bool operator() (GP* a, GP* b){   //默认是less函数 //返回true时，a的优先级低于b的优先级（a排在b的后面）
        if(a->GetCostF() > b->GetCostF())
            return true;
        if(a->GetCostF() == b->GetCostF() && a->GetCostH() > b->GetCostH())
            return true;
        return false;
    }
};

#endif